{include file="errors.tpl"}
<div class="clr"><br/></div>
<form method="get" name="transactions_form" action="{$GLOBALS.site_url}/payments/">
    <input type="hidden" name="action_name" id="action_name" value="" />
    <input type="hidden" name="sorting_field" id="sorting_field" value="{$sorting_field}" />
    <input type="hidden" name="sorting_order" id="sorting_order" value="{$sorting_order}" />
    <input type="hidden" name="page" id="page" value="{$currentPage}" />
    <div class="box" id="displayResults">
        <div class="box-header">
            <div style="display:inline-block;">
                <div class="actionWithSelected">
                    <input type="button" name="action" value="Delete" class="deletebutton" onclick="if ( confirm('Are you sure you want to delete selected transaction(s)?') ) submitForm('delete');" />
                </div>
            </div>
            <div class="pagination">
			{foreach from=$pages item=page}
				{if $page == $currentPage}
                    <strong>{$page}</strong>
					{else}
					{if $page == $totalPages && $currentPage < $totalPages-3} ... {/if}
                    <a href="?restore=1&amp;page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;transactions_per_page={$transactions_per_page}{$searchFields}">{$page}</a>
					{if $page == 1 && $currentPage > 4} ... {/if}
				{/if}
			{/foreach}
            </div>
            <div class="numberPerPage">
                [[per page:]]
                <select id="transactions_per_page" name="transactions_per_page" onchange="window.location = '?restore=1&amp;page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;transactions_per_page='+this.value;" class="perPage">
                    <option value="10" {if $transactions_per_page == 10}selected{/if}>10</option>
                    <option value="20" {if $transactions_per_page == 20}selected{/if}>20</option>
                    <option value="50" {if $transactions_per_page == 50}selected{/if}>50</option>
                    <option value="100" {if $transactions_per_page == 100}selected{/if}>100</option>
                </select>
            </div>
        </div>
        <div class="innerpadding">
            <div id="displayResultsTable">
                <table width="100%">
                    <thead>
                    <tr>
                        <th><input type="checkbox" id="all_checkboxes_control"></th>
                        <th>
                            <a href="?restore=1&amp;sorting_field=date&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'date'}DESC{else}ASC{/if}&amp;page={$currentPage}&amp;transactions_per_page={$transactions_per_page}">[[Date]]</a>
							{if $sorting_field == 'date'}
								{if $sorting_order == 'ASC'}
									<img src="{image}b_up_arrow.gif" alt="{tr}Up{/tr|escape:'html'}" title="{tr}Up{/tr|escape:'html'}" />
								{else}
									<img src="{image}b_down_arrow.gif" alt="{tr}Down{/tr|escape:'html'}" title="{tr}Down{/tr|escape:'html'}" />
								{/if}
							{/if}
                        </th>
                        <th>
                            <a href="?restore=1&amp;sorting_field=transaction_id&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'transaction_id'}DESC{else}ASC{/if}&amp;page={$currentPage}&amp;transactions_per_page={$transactions_per_page}">[[Transaction Id]]</a>
							{if $sorting_field == 'transaction_id'}
								{if $sorting_order == 'ASC'}
									<img src="{image}b_up_arrow.gif" alt="{tr}Up{/tr|escape:'html'}" title="{tr}Up{/tr|escape:'html'}" />
								{else}
									<img src="{image}b_down_arrow.gif" alt="{tr}Down{/tr|escape:'html'}" title="{tr}Down{/tr|escape:'html'}" />
								{/if}
							{/if}
                        </th>
                        <th>
                            <a href="?restore=1&amp;sorting_field=username&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'username'}DESC{else}ASC{/if}&amp;page={$currentPage}&amp;transactions_per_page={$transactions_per_page}">[[Username]]</a>
							{if $sorting_field == 'username'}
								{if $sorting_order == 'ASC'}
									<img src="{image}b_up_arrow.gif" alt="{tr}Up{/tr|escape:'html'}" title="{tr}Up{/tr|escape:'html'}" />
								{else}
									<img src="{image}b_down_arrow.gif" alt="{tr}Down{/tr|escape:'html'}" title="{tr}Down{/tr|escape:'html'}" />
								{/if}
							{/if}
                        </th>
                        <th>
                            <a href="?restore=1&amp;sorting_field=invoice_sid&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'invoice_sid'}DESC{else}ASC{/if}&amp;page={$currentPage}&amp;transactions_per_page={$transactions_per_page}">[[Description]]</a>
							{if $sorting_field == 'invoice_sid'}
								{if $sorting_order == 'ASC'}
									<img src="{image}b_up_arrow.gif" alt="{tr}Up{/tr|escape:'html'}" title="{tr}Up{/tr|escape:'html'}" />
								{else}
									<img src="{image}b_down_arrow.gif" alt="{tr}Down{/tr|escape:'html'}" title="{tr}Down{/tr|escape:'html'}" />
								{/if}
							{/if}
                        </th>
                        <th>
                            <a href="?restore=1&amp;sorting_field=payment_method&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'payment_method'}DESC{else}ASC{/if}&amp;page={$currentPage}&amp;transactions_per_page={$transactions_per_page}">[[Payment Method]]</a>
							{if $sorting_field == 'payment_method'}
								{if $sorting_order == 'ASC'}
									<img src="{image}b_up_arrow.gif" alt="{tr}Up{/tr|escape:'html'}" title="{tr}Up{/tr|escape:'html'}" />
								{else}
									<img src="{image}b_down_arrow.gif" alt="{tr}Down{/tr|escape:'html'}" title="{tr}Down{/tr|escape:'html'}" />
								{/if}
							{/if}
                        </th>
                        <th>
                            <a href="?restore=1&amp;sorting_field=amount&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'amount'}DESC{else}ASC{/if}&amp;page={$currentPage}&amp;transactions_per_page={$transactions_per_page}">[[Amount]]</a>
							{if $sorting_field == 'amount'}
								{if $sorting_order == 'ASC'}
									<img src="{image}b_up_arrow.gif" alt="{tr}Up{/tr|escape:'html'}" title="{tr}Up{/tr|escape:'html'}" />
								{else}
									<img src="{image}b_down_arrow.gif" alt="{tr}Down{/tr|escape:'html'}" title="{tr}Down{/tr|escape:'html'}" />
								{/if}
							{/if}
                        </th>

                    </tr>
                    </thead>
                    <tbody>
					{foreach from=$found_transactions_sids item=trans_sid name=transactions_block}
                    <tr class="{cycle values="oddrow,evenrow"}">
                        <td><input type="checkbox" name="transactions[{$trans_sid}]" value="1" id="checkbox_{$smarty.foreach.transactions_block.iteration}" /></td>
                        <td>{display property='date' object_sid=$trans_sid}</td>
                        <td>{display property='transaction_id' object_sid=$trans_sid}</td>
                        <td>
                            <a href="{$GLOBALS.site_url}/edit-user/?user_sid={display property='user_sid' object_sid=$trans_sid}">{display property='username' object_sid=$trans_sid}</a>
                        </td>
						{display property='invoice_sid' object_sid=$trans_sid assign=invoice_sid}
                        <td>[[Payment for Invoice #]]&nbsp;<a href="{$GLOBALS.site_url}/edit-invoice/?sid={$invoice_sid}">{$invoice_sid}</a></td>
                        <td>{display property='payment_method' object_sid=$trans_sid}</td>
                        <td>{$GLOBALS.settings.transaction_currency}{display property='amount' object_sid=$trans_sid}</td>
                    </tr>
					{/foreach}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="box-footer">
            <div class="actionWithSelected">
                <input type="button" name="action" value="Delete" class="deletebutton" onclick="if ( confirm('Are you sure you want to delete selected transaction(s)?') ) submitForm('delete');" />
            </div>
            <div class="numberPerPage">
                [[per page:]]
                <select id="transactions_per_page" name="transactions_per_page" onchange="window.location = '?restore=1&amp;page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;transactions_per_page='+this.value;" class="perPage">
                    <option value="10" {if $transactions_per_page == 10}selected{/if}>10</option>
                    <option value="20" {if $transactions_per_page == 20}selected{/if}>20</option>
                    <option value="50" {if $transactions_per_page == 50}selected{/if}>50</option>
                    <option value="100" {if $transactions_per_page == 100}selected{/if}>100</option>
                </select>
            </div>
        </div>
    </div>
</form>

<script>
    var total={$smarty.foreach.transactions_block.total};
	{literal}

    function set_checkbox(param) {
        for (i = 1; i <= total; i++) {
            if (checkbox = document.getElementById('checkbox_' + i))
                checkbox.checked = param;
        }
    }

    $("#all_checkboxes_control").click(function() {
        if ( this.checked == false)
            set_checkbox(false);
        else
            set_checkbox(true);
    });

    function submitForm(action) {
        document.getElementById('action_name').value = action;
        var form = document.transactions_form;
        form.submit();
    }
	{/literal}
</script>